import {getAllPosition,getUserList,getAllRoleAndUser} from '@/apilist/public'
import {workList, addWork,workDetail} from '@/apilist/WorkFlow'
import {getJobList} from '@/apilist/Job'
import {getCompanyList} from "@/apilist/Company";
import {getDeptList, getTicketList,getCityList,getLimitList,getSupplies,rateList} from '@/apilist/SystemSetting'
import {getPositionMappingList} from '@/apilist/Job'

const state = {
  position_list: [],//职位列表
  userList: [],//用户列表

  user_all: [],
  position_all: [],
  company_all:[],

  work: {
    work_list: [],
    work_state_list: [],
    page: 1,
    pagesize: 10,
    total:0,
    work_type_list: [],
  },

  work_detail:{
    name:'',
    desc:'',
    gsid: '',
    workList: [],
    workRow: 0,
    userList: [],
    id: 0,
    status: 0,
  },//流程详情

  //职位列表
  job: {
    jobList: [],
    statusList: [],
    page: 1,
    pagesize: 10,
    total: 0,
    fzjl_list: [],
    zjl_list: [],
    cw_list: [],
    cg_list: [],
    cgzj_list:[],
    xz_list: [],
    cn_list: [],
    sj_list: [],
    dept_list: [],
    sybid_list: [],
  },

  //公司列表
  company: {
    companyList : [],
    statusList: [],
    page: 1,
    page_size: 10,
    total: 0,
  },
  //部门设置
  deptList: [],
  deptTotal: 0,

  //客户设置
  ticketList: [],
  ticketTotal: 0,

  cityList: [],
  cityTotal: 0,
  cityLevelList: [],

  limit: {
    list: [],
  },
  map: {
    list: [],
    positionList: [],
    total: 0
  },

  supply: {
    list: [],
    total: 0,
  },
  currency: {
    list: [],
    total: 0,
  },

};

const mutations = {

  //获取职位列表
  getPositionMutations(state,data){
    state.position_list = data.list.position
  },

  //获取用户列表
  getAllRoleAndUserMutations(state,data){
    state.user_all = data.list.user_all
    state.position_all = data.list.position_all
    state.company_all = data.list.company_all
  },
  //获取流程列表
  getWorkListMutations(state,data){
    state.work.work_list = data.data
    state.work.work_state_list = data.work_state_list
    state.work.page = data.current_page
    state.work.pagesize = data.per_page
    state.work.total = data.total
    state.work.work_type_list = data.work_type_list
  },
  //流程详情
  getWorkDetailMutations(state,data){
    //console.log(data)
    state.work_detail.name = data.name
    state.work_detail.desc = data.desc
    state.work_detail.gsid = data.gsid
    state.work_detail.workList = data.workList
    state.work_detail.workRow = data.workRow
    state.work_detail.id = data.id
    state.work_detail.status = data.status
    state.work_detail.userList = data.userList

  },
  //职位列表
  getJobListMutations(state,data){
    state.job.jobList = data.data
    state.job.page = data.current_page
    state.job.pagesize = data.per_page
    state.job.total = data.total
    state.job.statusList = data.status_list
  },
  //公司列表
  getCompanyListMutations(state,data){
    state.company.companyList = data.data
    state.company.page = data.current_page
    state.company.page_size = data.per_page
    state.company.total = data.total
    state.company.statusList = data.status_list
    state.company.fzjl_list = data.fzjl_list
    state.company.zjl_list = data.zjl_list
    state.company.cw_list = data.cw_list
    state.company.cg_list = data.cg_list
    state.company.cgzj_list = data.cgzj_list
    state.company.xz_list = data.xz_list
    state.company.cn_list = data.cn_list
    state.company.sj_list = data.sj_list
    state.company.dept_list = data.dept_list
    state.company.sybid_list = data.sybid_list
  },
  //部门列表
  getDeptListMutations(state,data){
    console.log('mutations: ',data.data)
    state.deptList = data.data
    state.deptTotal = data.total
    //this.$forceUpdate()
  },

  //客户设置
  getTicketMutations(state,data){
    // console.log('mmmmmmmmmmmmmmmmm: \n', state)
    state.ticketList = data.list.data
    state.ticketTotal = data.list.total
  },
  //获取城市列表
  getCityMutations(state,data){
    // console.log('mmmmmmmmmmmmmmmmm: \n', state)
    state.cityList = data.data
    state.cityTotal = data.total
    state.cityLevelList = data.city_list
  },

  getLimitMutations(state,data){
    state.limit.list = data
  },

  getPositionMappingListMutations(state,data)
  {
    state.map.list = data.data;
    state.map.total = data.total;
    state.map.positionList = data.position_list;
  },

  //供应商列表
  getSuppliesMutations(state,data){
    state.supply.list = data.list
    state.supply.total = data.total
  },

  getRateListMutations(state,data){
    state.currency.list = data.list
    state.currency.total = data.total
  },
};

const actions = {
  //获取职位列表
  async getPositionAction(context,data){
    let res = await getAllPosition(data)
    context.commit('getPositionMutations',res.data)
  },
  //获取所有用户职位列表
  async getAllRoleAndUserAction(context,data){
    let res = await getAllRoleAndUser(data)
    //console.log(res.data);
    context.commit('getAllRoleAndUserMutations',res.data);
  },
  //获取流程表
  async getWorkListAction(context,data){
    let res = await workList(data)
    context.commit('getWorkListMutations',res.data)
  },
  //获取流程详情
  async getWorkDetailAction(context,data){
    let res = await workDetail(data)
    //console.log('RES: '+ res)
    context.commit('getWorkDetailMutations',res.data)
  },
  //获取职位列表
  async getJobListAction(ctx,data){
    let res = await getJobList(data)
    ctx.commit('getJobListMutations',res.data)
  },
  async getCompanyListActions(ctx,data){
    let res = await getCompanyList(data)
    ctx.commit('getCompanyListMutations',res.data)
  },
  //获取部门列表
  async getDeptListAction(ctx,data){
    let res = await getDeptList(data)
    //console.log('action: ',res.data)
    ctx.commit('getDeptListMutations',res.data)
  },

  //获取客户列表
  async getTicketListAction(ctx,data){
    let res = await getTicketList(data)
    // console.log('action: ',res.data)
    ctx.commit('getTicketMutations',res.data)
  },

  //获取城市列表
  async getCityListAction(ctx,data){
    let res = await getCityList(data)
    //console.log('action: ',res.data)
    ctx.commit('getCityMutations',res.data)
  },

  //获取城市列表
  async getLimitAction(ctx,data){
    let res = await getLimitList(data)
    //console.log('action: ',res.data)
    ctx.commit('getLimitMutations',res.data)
  },

  async getPositionMappingListAction(ctx,data)
  {
    let res = await getPositionMappingList(data);
    ctx.commit('getPositionMappingListMutations',res.data);
  },

  async getSupplyAction(ctx,data){
    let res = await getSupplies(data)
    ctx.commit('getSuppliesMutations',res.data);
  },
  async getRateListAction(ctx,data){
    let res = await rateList(data)
    ctx.commit('getRateListMutations',res.data);
  },
};


export default {
  namespaced: true,
  state,
  mutations,
  actions
}
